package com.sundablog.controller.systemsetup.basicsetup.blogroll;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sundablog.pojo.Blogroll;
import com.sundablog.result.BaseResult;
import com.sundablog.result.LayUiResult;
import com.sundablog.service.systemsetup.basicsetup.blogroll.BlogrollService;
import cn.hutool.extra.servlet.ServletUtil;

/**
 * 友情链接Controller层
 * @ClassName:  BlogrollController   
 * @Description:友情链接Controller层
 * @author: 哒哒 
 * @date:   2017年12月21日 下午11:36:02   
 *     
 * @Copyright: 2017 www.sundablog.com Inc. All rights reserved.
 */

@RequestMapping("/systemsetup/basicsetup/blogroll")
@Controller
public class BlogrollController {
	
	@Autowired
	private BlogrollService blogrollService;
	
	/**
	 * 友情链接界面显示
	 * @Title: showIndex   
	 * @Description: 友情链接界面显示
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequestMapping("/index")					  
	@RequiresPermissions("systemsetup_basicsetup_blogroll_index")
	public String showIndex() {
		return "/systemsetup/basicsetup/blogroll/index";
	}
	
	/**
	 * 分页
	 * @Title: findPagingQuery   
	 * @Description: 分页  
	 * @param: @param page
	 * @param: @param limit
	 * @param: @return      
	 * @return: LayUiResult      
	 * @throws
	 */
	@RequestMapping("/findPagingQuery")
	@RequiresPermissions("systemsetup_basicsetup_blogroll_findPagingQuery")
	@ResponseBody
	public LayUiResult findPagingQuery(@RequestParam(value="page", defaultValue="1") int page,@RequestParam(value="limit", defaultValue="10") int limit) {
		LayUiResult layUiResult = blogrollService.findPagingQuery(page, limit);
		return layUiResult;
	}
	
	/**
	 * 添加界面显示
	 * @Title: showAdd   
	 * @Description: 添加界面显示  
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_basicsetup_blogroll_addIndex")
	@RequestMapping("/addIndex")
	public String showAdd() {
		return "/systemsetup/basicsetup/blogroll/add";
	}
	
	/**
	 * 添加一条友情链接
	 * @Title: addBlogroll   
	 * @Description: 添加一条友情链接   
	 * @param: @param blogroll
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("addBlogroll")
	@RequiresPermissions("systemsetup_basicsetup_blogroll_addBlogroll")
	@ResponseBody
	public BaseResult addBlogroll(Blogroll blogroll) {
		int i = blogrollService.addBlogroll(blogroll);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.addSuccess);
		} else {
			return BaseResult.build(201, BaseResult.addFail);
		}
		
	}
	
	/**
	 * 修改界面显示
	 * @Title: updateIndex   
	 * @Description: 修改界面显示  
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_basicsetup_blogroll_edit")
	@RequestMapping("/edit")
	public String showEdit() {
		return "/systemsetup/basicsetup/blogroll/edit";
	}
	
	/**
	 * 修改
	 * @Title: updateBlogroll   
	 * @Description: 修改 
	 * @param: @param blogroll
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("/updateBlogroll")
	@RequiresPermissions("systemsetup_basicsetup_blogroll_updateBlogroll")
	@ResponseBody
	public BaseResult updateBlogroll(Blogroll blogroll) {
		int i = blogrollService.updateBlogroll(blogroll);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.updataSuccess);
		} else {
			return BaseResult.build(200, BaseResult.updataFail);
		}
	}
	
	
	/**
	 * 根据ID获取一条数据
	 * @Title: getByIdBlogroll   
	 * @Description: 据ID获取一条数据
	 * @param: @param id
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("/getByBlogroll")
	@RequiresPermissions("systemsetup_basicsetup_blogroll_getByBlogroll")
	@ResponseBody
	public BaseResult getByIdBlogroll(int id) {
		Blogroll blogroll = blogrollService.getBlogrollById(id);
		return BaseResult.build(200, "", blogroll);
	}
	
	
	/**
	 * 友情链接删除
	 * @Title: delectBlogroll   
	 * @Description: 友情链接删除   
	 * @param: @param id
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("/delectBlogroll")
	@RequiresPermissions("systemsetup_basicsetup_blogroll_delectBlogroll")
	@ResponseBody
	public BaseResult delectBlogroll(int id) {
		int i = blogrollService.delectBlogrollById(id);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.delectSuccess);
		} else {
			return BaseResult.build(201, BaseResult.delectFail);
		}
	}

	
	/**
	 * 修改界面显示
	 * @Title: showDetail   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_basicsetup_blogroll_showDetail")
	@RequestMapping("/showDetail")
	public String showDetail() {
		return "/systemsetup/basicsetup/blogroll/detail";
	}
}
